package wwl.lsf.hellospringboot.test.nio.nio入门;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class NIOClient {

  public static void main(String[] args) throws Exception {

    SocketChannel socketChannel = SocketChannel.open();

    socketChannel.configureBlocking(false);

    InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 9999);

    if (!socketChannel.connect(inetSocketAddress)) {

      while (!socketChannel.finishConnect()) {
        System.out.println("Client 连接服务器的同时,还能干一些别的事情");
      }

      String msg = "Hello 我是客户端";

      ByteBuffer wrap = ByteBuffer.wrap(msg.getBytes());

      socketChannel.write(wrap);

      System.in.read();

    }


  }

}
